<html>
<head><meta charset="utf-8"><title>Debugging failed assertion · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html">Debugging failed assertion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232388639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232388639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232388639">(Mar 30 2021 at 08:08)</a>:</h4>
<p>Hi, I'm trying to debug the error: <code>Assertion `isa&lt;X&gt;(Val) &amp;&amp; "cast&lt;Ty&gt;() argument of incompatible type!"' failed.</code> from <a href="https://github.com/rust-lang/rust/pull/81469#issuecomment-809428126">https://github.com/rust-lang/rust/pull/81469#issuecomment-809428126</a>. I thought this was an LLVM bug and followed the <a href="https://rustc-dev-guide.rust-lang.org/backend/debugging.html">Debugging LLVM guide</a>. When adding the "--emit=llvm-ir", the abort seems to happen <em>before</em> the IR is created (I can see the .ll for other crates built before it).<br>
I thought LLVM was only used after the IR was generated. What am I missing? Any idea on how to debug this? Thanks.</p>



<a name="232391425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232391425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232391425">(Mar 30 2021 at 08:34)</a>:</h4>
<p><code>--emit=llvm-ir</code> shows the ir after optimizations. You can use <code>-Cno-prepopulate-passes</code> to disable the optimization passes that run even when optimizations are "disabled".</p>



<a name="232392261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232392261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232392261">(Mar 30 2021 at 08:43)</a>:</h4>
<p>Thanks, I'll try that.</p>



<a name="232435427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232435427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232435427">(Mar 30 2021 at 14:33)</a>:</h4>
<p>So here are the different options I now have: <code>-C no-prepopulate-passes --emit=llvm-ir -C passes=name-anon-globals -C save-temps</code>. But again, the abort seems to happen before any kind of output (except the .d) is generated. No .ll, no .bc.</p>



<a name="232438694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232438694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232438694">(Mar 30 2021 at 14:51)</a>:</h4>
<p><code>env RUSTC_LOG=rustc_codegen_ssa=info rustc</code> should give you the concrete instance that is being codegened just before the crash</p>



<a name="232440947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232440947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232440947">(Mar 30 2021 at 15:02)</a>:</h4>
<p>Thanks, trying now.</p>



<a name="232452171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232452171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232452171">(Mar 30 2021 at 16:09)</a>:</h4>
<p>If you can reproduce this, I would look at debug logs around <code>get_fn</code> / <code>declare_fn</code> / <code>declare_raw_fn</code> and find out what is being declared and with what type and why it doesn't match the previous declaration (I would suspect personality function).</p>



<a name="232543665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232543665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232543665">(Mar 31 2021 at 06:44)</a>:</h4>
<div class="codehilite"><pre><span></span><code>INFO rustc_codegen_ssa::base codegen_instance(&lt;usize as Ord&gt;::max)
INFO rustc_codegen_ssa::base codegen_instance(core::cmp::max::&lt;usize&gt;)
INFO rustc_codegen_ssa::base codegen_instance(core::cmp::impls::&lt;impl Ord for usize&gt;::cmp)
INFO rustc_codegen_ssa::base codegen_instance(core::cmp::max_by::&lt;usize, for&lt;&#39;r, &#39;s&gt; fn(&amp;&#39;r usize, &amp;&#39;s usize) -&gt; core::cmp::Ordering {&lt;usize as Ord&gt;::cmp}&gt;)
</code></pre></div>



<a name="232588813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232588813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232588813">(Mar 31 2021 at 13:18)</a>:</h4>
<p>With rustc_codegen_llvm logs, there is :</p>
<div class="codehilite"><pre><span></span><code>INFO rustc_codegen_ssa::base codegen_instance(core::cmp::max_by::&lt;usize, for&lt;&#39;r, &#39;s&gt; fn(&amp;&#39;r usize, &amp;&#39;s usize) -&gt; core::cmp::Ordering {&lt;usize as Ord&gt;::cmp}&gt;)
DEBUG rustc_codegen_llvm::callee get_fn(instance=Instance { def: Item(WithOptConstParam { did: DefId(1:2543 ~ core[f647]::cmp::max_by), const_param_did: None }), substs: [usize, for&lt;&#39;r, &#39;s&gt; fn(&amp;&#39;r usize, &amp;&#39;s usize) -&gt; core::cmp::Ordering {&lt;usize as core::cmp::Ord&gt;::cmp}] })
DEBUG rustc_codegen_ssa::mir fn_abi: FnAbi   [....truncated here....]
DEBUG rustc_codegen_llvm::declare declare_raw_fn(name=&quot;rust_eh_personality&quot;, ty=i32 (...))
</code></pre></div>
<p>So yes, a declare_raw_fn on personality.  What does that mean?</p>



<a name="232590515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232590515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232590515">(Mar 31 2021 at 13:28)</a>:</h4>
<p>I think I know what happens. Previously <code>eh_personality</code> wasn't used in <code>panic_abort</code> and now it is for some reason. The <code>eh_personality</code> defined by <code>panic_abort</code> doesn't take any arguments as it aborts immediately and at assembly level it doesn't matter how many arguments it takes. Now that it is actually used, the code emitting the reference uses the real function signature, which conflicts with the previous definition in the same codegen unit.</p>



<a name="232590686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232590686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232590686">(Mar 31 2021 at 13:29)</a>:</h4>
<p>I think <code>eh_personality</code> is now used due to importing an <code>#[inline]</code> function from a crate that was compiled with <code>-Cpanic=unwind</code>.</p>



<a name="232590960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232590960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232590960">(Mar 31 2021 at 13:30)</a>:</h4>
<p>I think <a href="https://github.com/rust-lang/rust/blob/a5029ac0ab372aec515db2e718da6d7787f3d122/compiler/rustc_codegen_ssa/src/mir/block.rs#L115">https://github.com/rust-lang/rust/blob/a5029ac0ab372aec515db2e718da6d7787f3d122/compiler/rustc_codegen_ssa/src/mir/block.rs#L115</a> or something like that will need to be changed to use <code>call</code> instead of <code>invoke</code> for all function calls in <code>-Cpanic=abort</code> crates. Not just when the MIR doesn't have a cleanup target for the call.</p>



<a name="232607710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232607710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232607710">(Mar 31 2021 at 15:07)</a>:</h4>
<p>Right, <code>Vec::new</code> is inline, that explains it.</p>



<a name="232608866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232608866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232608866">(Mar 31 2021 at 15:14)</a>:</h4>
<p>You could use <code>malloc</code> and <code>memcpy</code> instead of <code>Vec</code>. No need to free the memory. (if allowed at all)</p>



<a name="232610462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232610462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232610462">(Mar 31 2021 at 15:22)</a>:</h4>
<p>As in <a href="https://doc.rust-lang.org/alloc/alloc/fn.alloc.html">https://doc.rust-lang.org/alloc/alloc/fn.alloc.html</a> ? I would still need to call Layout::new which is also inline?</p>



<a name="232617399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Debugging%20failed%20assertion/near/232617399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Debugging.20failed.20assertion.html#232617399">(Mar 31 2021 at 16:02)</a>:</h4>
<p>You can call plain <code>malloc</code> here as you already know that libc is available.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>